{extend name="public:base" /}{block name="css"}
<link rel="stylesheet" type="text/css" href="__ADMIN__/css/style.css">
<link href="__ADMIN__/css/tree.css" rel="stylesheet">
{/block}{block name="content"}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form class="layui-form" method="post">
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">名称</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="username" placeholder="请输入名称" value="{$info.username}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">账号</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="account" placeholder="请输入账号" value="{$info.account}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        {if !input('id')}
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">密码</label>
                                <div class="col-sm-3">
                                    <input type="password" class="form-control" name="password" placeholder="请输入密码" value="{:thinkDecrypt($info.password)}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">确认密码</label>
                                <div class="col-sm-3">
                                    <input type="password" class="form-control" name="re_password" placeholder="请确认密码" value="{:thinkDecrypt($info.password)}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>
                        {/if}

                        {notempty name="one_list"}
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">管理门店</label>
                                <div class="col-sm-3">
                                    {volist name="one_list" id="v" key='k'}
                                    <div class="one box {$k > 1 ? 'box-top-10' : ''}">
                                        <div class="top-menu">
                                            <div class="top-module">
                                                <div class="checkbox-input">
                                                    <input class="one_check" type="checkbox" value="{$v.id}" onclick="oneTreeAll(this, '{$k - 1}')">
                                                </div>
                                                <span class="checkbox-name">{$v.name}</span>
                                            </div>
                                        </div>

                                        <!-- 循环第2级菜单 -->
                                        {notempty name="v.two_list"}
                                        {volist name="v.two_list" id='vo' key='ke'}
                                        <div class="two">
                                            <div class="next">
                                                <div class="group-menu">
                                                    <div class="module">
                                                        <div class="checkbox-input">
                                                            <input class="two_check" type="checkbox" value="{$vo.id}" onclick="twoTreeAll(this, '{$k - 1}', '{$ke - 1}')">
                                                        </div>
                                                        <span class="checkbox-name">{$vo.name}</span>
                                                    </div>
                                                </div>
                                                <div style="clear: both"></div>

                                                <!-- 循环第3级菜单 -->
                                                {notempty name="vo.three_list"}
                                                {volist name="vo.three_list" id="val" key='kk'}
                                                <div class="three">
                                                    <div class="list-menu">
                                                        <div class="module">
                                                            <div class="checkbox-input">
                                                                <input name="shop_ids[]" class="three_check" type="checkbox" value="{$val.id}" onclick="threeTreeAll(this, '{$k - 1}', '{$ke - 1}', '{$kk - 1}')">
                                                            </div>
                                                            <span class="checkbox-name">{$val.name}</span>
                                                        </div>
                                                    </div>
                                                    <div style="clear: both"></div>
                                                </div>
                                                {/volist}
                                                {/notempty}
                                            </div>
                                        </div>
                                        {/volist}
                                        {/notempty}
                                    </div>
                                    {/volist}
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>
                        {/notempty}

                        <input type="hidden" name="id" value="{:input('id')}">
                        <input type="hidden" id="initialChannelId" value="{$info.up_channel_user_id|default=0}">

                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button type="button" class="btn btn-w-m btn-default back-page">返回</button>
                                <button type="button" class="btn btn-w-m btn-primary ajax-post">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name='js'}
<script src="__ADMIN__/js/auth_menu.js"></script>
<script>
    function updateOneStatus(oneBox) {
        var twoChecks = oneBox.find('.two_check');
        var threeChecks = oneBox.find('.three_check');
        var checkedCount = threeChecks.filter(':checked').length;
        var oneCheck = oneBox.find('.one_check');
        
        if (checkedCount === 0) {
            oneCheck.prop('checked', false);
        } else if (checkedCount === threeChecks.length) {
            oneCheck.prop('checked', true);
        } else {
            oneCheck.prop('checked', false);
        }
    }
    
    function updateTwoStatus(twoBox) {
        var threeChecks = twoBox.find('.three_check');
        var checkedCount = threeChecks.filter(':checked').length;
        var twoCheck = twoBox.find('.two_check');
        
        if (checkedCount === 0) {
            twoCheck.prop('checked', false);
        } else if (checkedCount === threeChecks.length) {
            twoCheck.prop('checked', true);
        } else {
            twoCheck.prop('checked', false);
        }
    }
    
    // 页面加载完成后，根据后台返回的check_shop_ids默认选中复选框
    $(function() {
        // 获取后台返回的选中的shop_ids
        var check_shop_ids = {$check_shop_ids} || [];

        if (check_shop_ids && check_shop_ids.length > 0) {
            // 遍历所有三级菜单复选框
            $('input.three_check').each(function() {
                var shop_id = $(this).val();
                // 如果当前shop_id在选中列表中，则选中它
                if (check_shop_ids.indexOf(parseInt(shop_id)) !== -1) {
                    $(this).prop('checked', true);
                }
            });
            
            // 更新二级菜单状态
            $('.two').each(function() {
                updateTwoStatus($(this));
            });
            
            // 更新一级菜单状态
            $('.one').each(function() {
                updateOneStatus($(this));
            });
        }
        
        // 返回按钮点击事件
        $('.back-page').on('click', function() {
            window.history.back();
        });
    });
</script>
{/block}